const App = {
    data() {
        return {
            photo,
            dataForm:{

            },
            tableData:[],
            ACCESSTOKEN:'',
            total: 0,
            loading: false,
            tableData:[],
            tabs:{},
            action:'1',
        }
    },
    beforeCreate() {
        function setRem() {
            const designWidth = 750; // 设计稿宽度（rpx）
            const maxWidth = 540; // 可选：限制最大宽度（如手机端常见值）
            const screenWidth = Math.min(window.innerWidth, maxWidth);
            const scale = screenWidth / designWidth;
            document.documentElement.style.fontSize = scale + 'px';
        }
        setRem();//1rem = 0.5px 对标小程序在 375px 宽的屏幕上，1rpx = 0.5px（因为 750rpx / 375px = 2）
    },
    mounted() {
        let URL = window.location.href;
        this.ACCESSTOKEN = getQueryObject(URL, 'ACCESSTOKEN');
        this.dataForm.Merchant_SerialNumber = getQueryObject(URL, 'id1');
        this.dataForm.Room_Type_SerialNumber = getQueryObject(URL, 'id2');
        this.dataForm.House_Room_SerialNumber = getQueryObject(URL, 'id3');
        this.getList(this.dataForm);
    },
    methods: {
        getList(data) {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                method: "post",
                data: {
                    Data: 'room_type',
                    Condition: `Room_Type_SerialNumber='${data.Room_Type_SerialNumber}'`,
                },
                success: (res) => {
                    this.dataForm.Room_Type_Name = res[0].Room_Type_Name
                },
                complete: (XMLHttpRequest) => {
                    if (XMLHttpRequest.status == 302) {
                        wx.miniProgram.navigateTo({
                            url: miniProgram,
                        })
                    }
                },
            });
        },
        handleClick() {
            if (!this.dataForm.Guest_Name) {
                this.$message({
                    message: '请输入姓名',
                    type: 'warning'
                });
                return
            }
            if (!this.dataForm.ID_Card_Number) {
                this.$message({
                    message: '请输入身份证号',
                    type: 'warning'
                });
                return
            }
            if (!this.dataForm.Contact_Phone) {
                this.$message({
                    message: '请输入联系电话',
                    type: 'warning'
                });
                return
            }
            if (!this.dataForm.Check_In_Date) {
                this.$message({
                    message: '请选择入住时间',
                    type: 'warning'
                });
                return
            }
            if (!this.dataForm.Check_Out_Date) {
                this.$message({
                    message: '请选择离店时间',
                    type: 'warning'
                });
                return
            }
            if (!this.loading) {
                this.loading = true;
                let lJSONObject_DataSet = {
                    Add:{
                        room_type_check_ins:[this.dataForm]
                    }
                }
                this.submitSave(lJSONObject_DataSet, (res) => {
                    if (res.Status == 'success') {
                        this.$message({
                            message: '入住成功',
                            type: 'success'
                        });
                        // wx.miniProgram.navigateTo({
                        //     url: miniProgram,
                        // })
                        wx.navigateBack();
                    }
                    this.loading = false;
                })
            }
        },
        submitSave(Data, response) {
            const websocket = new WebSocketClient();
            websocket.init({
                url: ws + '/generalSave/' + getCookie('token'),
                onopen: () => {
                    let lJSONObject_DataSet = {
                        Data, AccessToken: getCookie('token')
                    }
                    websocket.send(JSON.stringify(lJSONObject_DataSet));
                },
                onmessage: (data) => {
                    try {
                        const res = JSON.parse(data);
                        websocket.close();
                        if (res.REDIRECT && res.REDIRECT == 'REDIRECT') {//重定向
                            wx.miniProgram.navigateTo({
                                url: miniProgram,
                            })
                        } else {
                            response ? response(res) : null;
                        }
                    } catch (error) { }
                },
            })
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");